<?php

namespace App\Http\Controllers\Api\V1;

use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

class MovieSignatureController extends BaseController
{

	/**
	 * [index 影片签名]
	 * @param  Request $request [description]
	 * @return [type]           [description]
	 */
    public function index(Request $request)
    {

    	// 用户id
    	$nns_user_id = $request->input('nns_user_id');
    	if (empty($nns_user_id)) {
    		return response()->json(['status' => '404', 'data' => '用户id不能为空!']);
    	}
    	// 视频id
    	$nns_cp_video_id = $request->input('nns_cp_video_id');
    	if (empty($nns_cp_video_id)) {
    		return response()->json(['status' => '404', 'data' => '视频id不能为空!']);
    	}
    	// 时间戳
    	$nns_timestamp = $request->input('nns_timestamp');
    	if (empty($nns_timestamp)) {
    		return response()->json(['status' => '404', 'data' => '时间戳不能为空!']);
    	}

    	// 读取配置
    	$config = app()->make('config');
    	// 秘钥
    	$auth_key = $config->get('custom.auth_key');
    	// cp_id
    	$nns_cp_id = $config->get('custom.cp_id');

    	// 拼装要加密的字符串
    	$signature = $auth_key . '$$' . $nns_cp_id . '$$' . $nns_user_id . '$$' . $nns_cp_video_id . '$$' . $nns_timestamp;

    	// 调用加密算法生成秘钥get_signature_aes128()|get_signature_hmac_sha256()
    	$signature = get_signature_aes128($auth_key, $signature);

        return response()->json(['status' => '200', 'data' => $signature]);
    }
}
